angular.module('myApp').component('about', {
  templateUrl:  'view/about.html',
  controller: function(PeopleService,MyFactory) {
    this.rowCollection = [
      {firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: 'whatever@gmail.com'},
      {firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: 'oufblandou@gmail.com'},
      {firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: 'raymondef@gmail.com'}
    ];

    var firstnames = ['Laurent', 'Blandine', 'Olivier', 'Max'];
    var lastnames = ['Renard', 'Faivre', 'Frere', 'Eponge'];
    var dates = ['1987-05-21', '1987-04-25', '1955-08-27', '1966-06-06'];
    var id = 1;

     function generateRandomItem(id) {

      var firstname = firstnames[Math.floor(Math.random() * 3)];
      var lastname = lastnames[Math.floor(Math.random() * 3)];
      var birthdate = dates[Math.floor(Math.random() * 3)];
      var balance = Math.floor(Math.random() * 2000);

      return {
        id: id,
        firstName: firstname,
        lastName: lastname,
        birthDate: new Date(birthdate),
        balance: balance,
          email:"abcd@qq.com"
      }
    }
    this.addRandomItem = function() {
      var item = generateRandomItem(id);
      console.log("item:"+item);
      this.rowCollection.push(item);
      id++;
    };

    this.removeRow = function(row) {
          var index = this.rowCollection.indexOf(row);
          if (index !== -1) {
              this.rowCollection.splice(index, 1);
          }
    }
    this.getPeople=function () {
        // var promise = PeopleService.getAllPeople();
        // console.log(promise);
       PeopleService.getAllPeople().then(function (people) {
           return PeopleService.getAllPeople();
          // console.log(people);
       }).then(function (people) {
           return PeopleService.getAllPeople();
           // console.log(people);
       }).then(function (people) {
            console.log(people);
       })
       ;

    }

      this.setPeopleServiceName=function () {
          console.log('修改前：PeopleService.name:'+PeopleService.name);
          PeopleService.name='aboutName';
          console.log('修改后：PeopleService.name:'+PeopleService.name);
      }

      this.setMyFactoryName=function () {
          console.log('修改前：MyFactory.name:'+MyFactory.name);
          MyFactory.name='aboutFactoryName';
          console.log('修改后：MyFactory.name:'+MyFactory.name);

      }


      var myList = this.lists = [];
      this.getAllPeople = function() {
          PeopleService.getAllPeople.then(function(res){
              myList=(res.data);
              for(var i=0; i < res.data.length; i++){
                  myList.push(res.data.lists[i]);
              }
              console.log(myList);

          });
      }

  }
})